package com.srcptit.java.training.kienbd.btvn1;

import java.lang.Math;

public class Muc1Bai7{
	static int f[]={0,1,1,2,3,5,8,13,21,34,55,89};//Khoi tao day Folnacci.
	static boolean Songuyento(int n){//Kiem tra so nguyen to.
            if( n<2 )   return false;
            for(int i=2;i<=Math.sqrt(n);i++)
            if( n%i==0 )	return false;
            return true;
	}
	static boolean Xet(int sum){//Kiem tra Sum co nam trong day Fibolnacci ko?
            for(int i=1;i<=11;i++)
            if( f[i]==sum )	return true;
            return false;
	}
	static boolean Kiemtra(int n){//Kiem tra so thuan nghich va tong cac chu so.
            if( Songuyento(n)==false )	return false;
            int sodao=0;
            int sum=0;//Tong cac chu so.
            int m = n, du;
            while(m>0){
		du=m%10;
		sodao=sodao*10+du;
		sum=sum+du;
		m=m/10;
            }
            if( sodao==n && Xet(sum)==true )    return true;
            return false;
        }
	public static void main(String args[]){//Loc ra so nguyen to...
            System.out.println("Cac so thoa man.");
            int dem = 0;
            for(int i=10000;i<=9999999;i++)
		if( Kiemtra(i)==true ){ 
                    System.out.println(i);
                    dem++;
                }
            System.out.println("Co tat ca "+dem+" so.");
        }
}
